<template>
	<view class="myInquiry-wrap">
		<view class="myInquiry-tab"><u-tabs v-model="activeTab" :scroll="false" :tabs="['全部','待接诊', '问诊中', '已结束']" @change="tabChange"></u-tabs></view>

		<scroll-view show-scrollbar="false" class="myInquiry-list" scroll-y @scrolltolower="scrollLoading()">
			<u-doctor-inquiry-order v-for="(item, index) in dataList" :key="index" :data="item" @paySuccess="initData"></u-doctor-inquiry-order>

			<u-empty-state v-if="dataTotalPage == 0" value="暂无相关问诊订单"></u-empty-state>
			<uni-load-more v-if="dataTotalPage > 1" :status="dataLoading"></uni-load-more>
		</scroll-view>
	</view> 
</template>

<script>
import uTab from '@/components/u-tabs/u-tabs.vue';
import uDoctorInquiryOrder from '../components/u-doctor-inquiry-order/u-doctor-inquiry-order.vue';
import uniLoadMore from '@/components/uni/uni-load-more/uni-load-more.vue';
import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
export default {
	components: {
		uTab,
		uDoctorInquiryOrder,
		uniLoadMore,
		uEmptyState
	},
	data() {
		return {
			activeTab: 0, 
			pageNo: 1,
			pageSize: 20,
			dataTotalPage: 1, //数据总数
			dataLoading: 'loading', //数据加载
			dataList: []
		};
	},
	onLoad(option) {
		this.doctorQuestionOrder();
	},
	onShow() {},
	methods: {
		tabChange(e) {
			this.activeTab = e;
			this.pageNo = 1;
			this.dataList = [];
			this.dataTotalPage = 1;
			this.scrollLoading();
		},
		
		initData(e) {
			this.pageNo = 1;
			this.dataList = [];
			this.dataTotalPage = 1;
		
			this.scrollLoading();
		},

		//问诊订单列表
		doctorQuestionOrder() {
			const params = {
				orderType: '0,1',
				pageNo: this.pageNo,
				pageSize: this.pageSize
			};
			
			
			switch (this.activeTab) {
				case 0:
					break;
				case 1:
					params.status = 0;
					break;
				case 2:
					params.status = 1;
					break;
				case 3:
					params.status = 3;
					break;
			}

			this.$api
				.doctorQuestionOrder({
					params: params
				})
				.then(res => {
					if (res.code == 200) {
						this.dataTotalPage = res.result.pages;

						if (this.pageNo == 1) {
							this.dataList = res.result.records;
						} else {
							this.dataList = this.dataList.concat(res.result.records);
						}

						if (res.result.current >= res.result.pages) {
							this.dataLoading = 'noMore';
						} else {
							this.dataLoading = 'loading';
						}
						this.pageNo++;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//滚动加载
		scrollLoading() {
			if (this.pageNo <= this.dataTotalPage) {
				this.doctorQuestionOrder();
			}
		}
	}
};
</script>

<style lang="less">
@import './myInquiry.less';
</style>
